#include <bits/stdc++.h>

using namespace std;
// ofstream output("out.out");

typedef struct Node {
    int val;
    Node *left;
    Node *right;
    Node() : val(0), left(nullptr), right(nullptr) {}
    Node(int x) : val(x), left(nullptr), right(nullptr) {}
    Node(int x, Node *left, Node *right) : val(x), left(left), right(right) {}
}*PNode;
void helperPrint(PNode root) {
    if (root == nullptr) { return; }
    cout << root->val << " ";
    helperPrint(root->left);
    helperPrint(root->right);
}
class Solution {
    int post_idx;
    unordered_map<int, int> idx_map;
    Node *helper(int idxl, int idxr, vector<int> &inorder, vector<int> &postorder) {
        if (idxl > idxr || post_idx < 0) {
            return nullptr;
        }
        // output << post_idx << endl;
        int nodeval = postorder[post_idx];
        Node *root = new Node(nodeval);
        int index = idx_map[nodeval];
        post_idx--;
        root->right = helper(index + 1, idxr, inorder, postorder);
        root->left = helper(idxl, index - 1, inorder, postorder);
        return root;
    }
public:

    PNode buildTree(vector<int> &inorder, vector<int> &postorder) {
        post_idx = (int)postorder.size() - 1;
        int i = 0;
        for (auto &val : inorder) {
            idx_map[val] = i++;
        }
        return helper(0, (int)inorder.size() - 1, inorder, postorder);
    }
};

int main() {
    vector<int> inorder, postorder;

    string readed;
    int num;

    getline(cin, readed);
    stringstream readedstream1(readed);
    while (readedstream1 >> num) {
        inorder.push_back(num);
    }

    getline(cin, readed);
    stringstream readedstream2(readed);
    while (readedstream2 >> num) {
        postorder.push_back(num);
    }

    helperPrint(Solution().buildTree(inorder, postorder));
    // output.close();

    //system("pause");
    return 0;
}